package com.lbx.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * @author 吕兵星
 * @date 2020/11/3 12:51
 */
@Service
public class MailService {
    @Autowired
    private JavaMailSenderImpl mailSender;

    public void sendMail(){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("TEST");
        message.setText("这是一个springboot测试邮件");
        message.setFrom("342561749@qq.com");
        message.setTo("342561749@qq.com");

        mailSender.send(message);
    }
    public void sendMail2() throws MessagingException {
        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setSubject("复杂测试");
        helper.setText("<p style='color:red'>测试HTML邮件</p>",true);
        helper.setFrom("342561749@qq.com");
        helper.setTo("342561749@qq.com");
        mailSender.send(message);
    }
}
